package com.zx.role.aop;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Component
@Slf4j
@Aspect
public class ZxAop {
    @Autowired
    HttpServletRequest request;

    @Around("@annotation(com.zx.role.aop.ZxLog)&&@annotation(zxLog)")
    public Object aop(ProceedingJoinPoint point,ZxLog zxLog) throws Throwable {
        String format = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        StringBuffer ip = request.getRequestURL();
        Object proceed = point.proceed();
        Object[] args = point.getArgs();
//        log.info("该方法的运行时间为："+format+"ip为："+ip+"  方法参数："+args
//                +"该方法的名称为："+zxLog.name()+"方法的返回值为："+proceed);
//        System.err.println("该方法的运行时间为："+format+"ip为："+ip+"  方法参数："+args
//                +"该方法的名称为："+zxLog.name()+"方法的返回值为："+proceed);
        return proceed;
    }

}
